(function($){
	var queue = [];
	var removeTimeoutId;

	Growl = function(options){
		var self = this;
		this.parent = $(document.body);

		function _initialize(options){
			this.message = '';

			this.element = $('<div class="growl" />');

			var msgEl = $('<div class="message" />');
			msgEl.appendTo(this.element);

			var closeBtn = $('<span class="btn-close icon-cross" />');
			closeBtn.bind('click',function(){
				self.remove();
			});
			closeBtn.prependTo(this.element);

			if(options){
				if(options.message){
					this.message = options.message;
					msgEl.html(this.message);
				}

				if(options.title){
					this.title = options.title;
					$('<h4 class="title">'+this.title+'</h4>').prependTo(this.element);
				}

				if(options.timeout && typeof options.timeout == 'number')
					this.timeout = options.timeout;

				this.parent = options.parent?options.parent:this.parent;
			}

			this.parent.append(this.element);

			queue.push(this);
			if(queue.length == 1)
				queue[0].show();
		}

		_initialize.apply(this,[options]);
	}

	Growl.prototype = {
		show : function(){
			var self = this;
			setTimeout(function(){
				self.element.css('webkitTransform','translate3d(-100%,0,0)')
			},10);
			if(self.timeout){
				removeTimeoutId = setTimeout(function(){
					self.remove();
				},this.timeout);
			}
		},
		remove : function(){
			var self = this;
			this.element.css('webkitTransform','');

			clearTimeout(removeTimeoutId);

			setTimeout(function(){
				self.element.remove();
				queue.shift();
				if(queue.length != 0){q=queue;
					queue[0].show();
				}
			},350)
		}
	};
	growl = function(options){
		return new Growl(options);
	}

	$.fn.growl = function(options){
		if(typeof options == 'string')
			options = {
				message : options
			};
		return growl(options?$.extend(options,{parent:this}):{parent:this});
	}
})(jq);
var q;